﻿// Inner Fire 游戏引擎库
// DxIniter 渲染器初始化功能
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 用于DirectX的渲染器。
// 此文件分装用于初始化功能
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-04-23

#pragma once

#include "dx_module.h"
#include <dxgi1_4.h>

namespace ifire::dx {
class DxIniter : public DxModule {
public:
  DxIniter(DxGraphics* dx);
  DxIniter(const DxIniter& rhs) = delete;
  DxIniter& operator=(const DxIniter& rhs) = delete;
  ~DxIniter() = default;

  void CreateDevice();
  void CreateCommandObjects();
  void FlushCommandQueue();
  void NextFence();

  // ------
  // 属性访问
  // ------
  inline ID3D12Device* Device() { return device_.Get(); }
  inline IDXGIFactory4* GetFactory() { return factory_.Get(); }
  inline ID3D12GraphicsCommandList* CommandList() { return cmd_list_.Get(); }
  inline ID3D12CommandQueue* GetCmdQueue() { return cmd_queue_.Get(); }
  inline ID3D12CommandAllocator* GetAllocator() { return cmd_allocator_.Get(); }
  inline ID3D12Fence* GetFence() { return fence_.Get(); }

private:  
  // 核心设备成员
  ComPtr<IDXGIFactory4> factory_;
  ComPtr<ID3D12Device> device_;
  ComPtr<IDXGIAdapter> warp_adapter_;

  // 用于命令队列
  ComPtr<ID3D12CommandQueue> cmd_queue_;
  ComPtr<ID3D12CommandAllocator> cmd_allocator_;
  ComPtr<ID3D12GraphicsCommandList> cmd_list_;

  // 用于Fence
  ComPtr<ID3D12Fence> fence_;
  UINT64 current_fence_;
};

} // namespace ifire::dx